<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>    
    <meta charset="UTF-8">
       
    <meta name="viewport" content="width=device-width, initial-scale=1, maximumscale=1">
       <title>Title</title>    
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
</head>
<body>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.12.3.min.js"></script>
<script th:inline="none">
    //Demo
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer
            , form = layui.form
            , table = layui.table
            , $ = layui.jquery;//引入jquery
        var id=$("#insureId").val();
        //根据父页面传来的id获取车辆信息并回填
        $.ajax({

            type:"get",
            url:"/insurerecord/insurerecordById",
            data:{id:id},
            success:function(resp){

                console.log(resp.data.insurerecord);
                var insurerecord=resp.data.insurerecord;
                $("#vid").val(insurerecord.vid);
                $(":text[name=insurenum]").val(insurerecord.insurenum);
                $("#starttime").val(insurerecord.starttime);
                $("#typeid").val(insurerecord.typeid);
                $(":text[name=money]").val(insurerecord.money);
                $("#companyid").val(insurerecord.companyid);
                $("#endtime").val(insurerecord.endtime);
                $("#driverid").val(insurerecord.driverid);


            }
        });

        $.ajax({
            type: "GET",
            url: "/vehiclefiles/selectVehicleAll",
            success: function (res) {
                var vehiclefiles = res.data.vehiclefilesList;
                if (vehiclefiles.length > 0) {
                    for (var i = 0; i < vehiclefiles.length; i++) {
                        var vehiclefile = vehiclefiles[i];
                        var sele='';
                        if(vehiclefile.id==$("#vid").val()){
                            sele='selected';
                        }
                        //追加，注意有坑，需要渲染下拉菜单
                        $("#vehiclenum").append("<option value='" + vehiclefile.id + "' selected='"+sele+"'>" + vehiclefile.vehiclenum + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/dictionary/dictionaryType14",
            success: function (res) {
                var dictionarys = res.data.dictionaryList;
                if (dictionarys.length > 0) {
                    for (var i = 0; i < dictionarys.length; i++) {
                        var dictionary = dictionarys[i];
                        var sele='';
                        if(dictionary.id==$("#typeid").val()){
                            sele='selected';
                        }
                        $("#typeid").append("<option value='" + dictionary.id + "' selected='"+sele+"'>" + dictionary.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        });
        $.ajax({
            type: "GET",
            url: "/dictionary/dictionaryType15",
            success: function (res) {
                var dictionarys = res.data.dictionaryList;
                if (dictionarys.length > 0) {
                    for (var i = 0; i < dictionarys.length; i++) {
                        var dictionary = dictionarys[i];
                        var sele='';
                        if(dictionary.id==$("#companyid").val()){
                            sele='selected';
                        }
                        $("#companyid").append("<option value='" + dictionary.id + "' selected='"+sele+"'>" + dictionary.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/driver/selectAllDriver",
            success: function (res) {
                var drivers = res.data.drivers;
                if (drivers.length > 0) {
                    for (var i = 0; i < drivers.length; i++) {
                        var driver = drivers[i];
                        var sele='';
                        if(driver.id==$("#driverid").val()){
                            sele='selected';
                        }
                        $("#driver").append("<option value='" + driver.id + "' selected='"+sele+"'>" + driver.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        });


    });
    var callbackdata=function(){
        var forms = $("#from2").serialize();
        return forms;
    }
</script>

<form class="layui-form" action="" method="" id="from2">
    <input type="hidden"   name="id" id="insureId">

        <div class="layui-form-item">
            <label class="layui-form-label">车牌号码</label>
            <div class="layui-input-block">
                <select lay-verify="required"  name="vid" id="vehiclenum">
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险编号</label>
            <div class="layui-input-block">
                <input type="text" name="insurenum" required  lay-verify="required" placeholder="请填写"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险开始日期</label>
            <div class="layui-input-block">
                <input type="date" name="starttime" required  lay-verify="required" placeholder="请输入"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险种类</label>
            <div class="layui-input-block">
                <select lay-verify="required"  name="typeid" id="typeid">
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">保险金额</label>
            <div class="layui-input-block">
                <input type="text" name="money" required  lay-verify="required" placeholder="填写金额"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险公司</label>
            <div class="layui-input-block">
                <select lay-verify="required"  name="companyid" id="companyid">
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">保险截止日期</label>
            <div class="layui-input-block">
                <input type="date" name="endtime" required  lay-verify="required" placeholder="请输入"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">经办人</label>
            <div class="layui-input-block">
                <select lay-verify="required" name="driverid"  id="driver">
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>

    </form>


</body>
</html>